import os
import sys


def checkNum(n: int):
    global arr
    if n in arr:
        return True
    if n == 1: return False
    if n <= 3: return True
    if n % 2 == 0: return False
    d = n - 1
    s = 0
    while d % 2 == 0:
        d //= 2
        s += 1
    for a in arr:
        x = pow(a, d, n)
        if x == 1 or x == n - 1:
            continue
        for _ in range(s - 1):
            x = pow(x, 2, n)
            if x == n - 1:
                break
        else:
            return False
    return True


arr = [2, 3, 5, 7, 11, 233]
t = int(input())
for _ in range(t):
    n = int(input())
    print(1 if checkNum(n) else 0)
